//
//  CycleCollectionViewCell.m
//  轮播scrollerView
//
//  Created by CheMiMacPro on 15/4/20.
//  Copyright (c) 2015年 CheMiMacPro. All rights reserved.
//

#import "CycleCollectionViewCell.h"

@implementation CycleCollectionViewCell
{
    UILabel *_titleLabel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        _imageView = [[UIImageView alloc] init];
        [self addSubview:_imageView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        _titleLabel.hidden = YES;
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_titleLabel];
    }
    return self;
}

- (void)setTitle:(NSString *)title
{
    _titleLabel.text = [NSString stringWithFormat:@"   %@", title];
}

// 滚动一个UIScrollView会触发layoutSubviews
- (void)layoutSubviews
{
    [super layoutSubviews];
    _imageView.frame = self.bounds;
    CGFloat titleLabelW = self.frame.size.width;
    CGFloat titleLabelH = 30;
    CGFloat titleLabelX = 0;
    CGFloat titleLabelY = self.frame.size.height - titleLabelH;
    _titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
    _titleLabel.hidden = !_titleLabel.text;
}




@end
